﻿
/*********************************************************************************
--时间：2011-12-27 21:11:22
--作者：jjpeng
--邮箱：ling121211@gmail.com
--说明：读取config配置文件中的节点值
--
*********************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Configuration;

namespace PCC.Framework.Config
{
    /// <summary>
    /// 读取web.config中的配置节点
    /// </summary>
    public class ConfigHelper
    {
        private static readonly SHConfigSection SHConfigInstance = null;

        static ConfigHelper()
        {
            SHConfigInstance = ConfigurationManager.GetSection("SHConfig") as SHConfigSection;
        }

        private ConfigHelper()
        { }

        /// <summary>
        /// 获取项目配置项值
        /// </summary>
        /// <param name="sectionName"></param>
        /// <returns></returns>
        public static string GetSystemSettings(string sectionName)
        {
            KeyValueConfigurationElement element = SHConfigInstance.SystemSettings[sectionName] as KeyValueConfigurationElement;
            if (element.Value == null)
            {
                return "";
            }
            return element.Value;
        }

        /// <summary>
        /// 获取项目配置项值
        /// </summary>
        /// <param name="sectionName">节点名称</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public static string GetSystemSettings(string sectionName, string defaultValue)
        {
            string ret = GetSystemSettings(sectionName);
            if (ret == "")
            {
                return defaultValue;
            }
            return ret;
        }

        /// <summary>
        /// 获取第三方配置项值
        /// </summary>
        /// <param name="sectionName">节点名称</param>
        /// <returns></returns>
        public static string GetReferenceSettings(string sectionName)
        {
            KeyValueConfigurationElement element = SHConfigInstance.ReferenceSettings[sectionName] as KeyValueConfigurationElement;
            if (element.Value == null)
            {
                return "";
            }
            return element.Value;
        }

        /// <summary>
        /// 获取第三方配置项值
        /// </summary>
        /// <param name="sectionName">节点名称</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public static string GetReferenceSettings(string sectionName, string defaultValue)
        {
            string ret = GetReferenceSettings(sectionName);
            if (ret == "")
            {
                return defaultValue;
            }
            return ret;
        }

        /// <summary>
        /// 获取框架设置项值
        /// </summary>
        /// <param name="sectionName">节点名称</param>
        /// <returns></returns>
        public static string GetFrameworkSettings(string sectionName)
        {
            KeyValueConfigurationElement element = SHConfigInstance.FrameworkSettings[sectionName] as KeyValueConfigurationElement;
            if (element.Value == null)
            {
                return "";
            }
            return element.Value;
        }

        /// <summary>
        /// 获取框架设置项值
        /// </summary>
        /// <param name="sectionName">节点名称</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        public static string GetFrameworkSettings(string sectionName, string defaultValue)
        {
            string ret = GetFrameworkSettings(sectionName);
            if (ret == "")
            {
                return defaultValue;
            }
            return ret;
        }
    }
}
